package cn.jbt.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.jbt.api.admin.annotation.Log;
import cn.jbt.api.admin.entity.XxlJobLog;
import cn.jbt.api.admin.service.IXxlJobLogService;
import cn.jbt.common.PageQryParam;
import cn.jbt.common.PageQryResult;
import com.alibaba.fastjson2.JSONObject;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/xxlJob/log")
@Slf4j
@AllArgsConstructor
public class XxlJobLogController {

    private final IXxlJobLogService iXxlJobLogService;

    @PostMapping("/list")
    @SaCheckPermission("xxlJob:log:list")
    @Log(bizType = "查询", bizName = "分页查询日志信息")
    public PageQryResult<XxlJobLog> getAllByPage(@Valid @RequestBody PageQryParam<XxlJobLog> pageQryParam) {
        return iXxlJobLogService.getAllByPage(pageQryParam);
    }

    @PostMapping("/kill/{id}")
    @SaCheckPermission("xxlJob:log:kill")
    @Log(bizType = "终止任务", bizName = "终止执行的任务")
    public void kill(@PathVariable Integer id) {
        iXxlJobLogService.kill(id);
    }

    /**
     * <h2>查询执行日志</h2>
     */
    @PostMapping("/execLog/{id}")
    public JSONObject execLog(@PathVariable Integer id) {
        return iXxlJobLogService.execLog(id);
    }

}
